package com.lzx.schedule;


import com.lzx.entity.Proxywebsite;
import com.lzx.service.IpService;
import com.lzx.service.ProxywebsiteService;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CrawlerJob extends QuartzJobBean {
    @Autowired
    AsyncService asyncService;
    @Autowired
    IpService ipService;
    @Autowired
    ProxywebsiteService proxywebsiteService;

    @Override
    protected void executeInternal (JobExecutionContext jobExecutionContext) throws JobExecutionException {
        System.out.println("定时任务开始");
        List<Proxywebsite> proxywebsites = proxywebsiteService.list();
        if(proxywebsites == null || proxywebsites.size() == 0){
            return ;
        }
        System.out.println("代理网站：" + proxywebsites);

        try{
            for(int i = 0; i< proxywebsites.size(); i++){
                Proxywebsite site = proxywebsites.get(i);
                asyncService.crawlerIp(site);
            }
        }catch (Exception e){
            e.printStackTrace();
        }




    }






}
